<!DOCTYPE html>
<title>Tests that moving a "video" in and out of an "iframe" does not trigger a crash.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<body>
<div></div>
<video></video>
<script>
async_test(function(t) {
    var iframe = document.createElement("iframe");
    iframe.src = "../../media-resources/resources/frame_size_change.webm";
    document.querySelector("div").appendChild(iframe);

    setTimeout(t.step_func(function() {
        var iframeContentDocument = iframe.contentDocument;
        var iframeDocumentElement = iframeContentDocument.documentElement;

        iframeContentDocument.onreadystatechange = function() {
            // Attempts to move the document body back into the iframe document.
            iframeContentDocument.appendChild(iframeDocumentElement);
        };

        // Moves the iframe body into the current document.
        document.body.appendChild(iframeContentDocument.firstChild);
        // Reload page.
        var url = location.href;
        var loadCount = 1;
        var queryIndex = url.indexOf("?");
        if (queryIndex >= 0) {
            loadCount = parseInt(url.substring(queryIndex + 1));
            // Enforce an arbitrary reload limit that is high enough to trigger previosly observed crashes.
            if (loadCount >= 10) {
                t.done();
                return;
            }

            url = url.substring(0, queryIndex);
        }

        location.href = url + "?" + (loadCount + 1);
    }), 20);
});
</script>